<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8"/>
        <title>数据上报管理</title>
        <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
        <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
        <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body>
    <div class="easyui-container-fluid">
        <div class="easyui-panel" style="border: none;">
            <div class="nav" id="nav"></div>
            <div class="easyui-panel" style="border: none;">
                <form id="ff">
                    <div style="margin-bottom:20px">
                        <label class="item-label">报告年份：</label>
                        <input type="text" id="year" name="reportYear" class="easyui-combobox" style="width: 100px;"/>
                        <span id="monthLabel">
	                        <label class="item-label">报告月份：</label>
	                        <input id="month" name="reportMonth" type="text" class="easyui-combobox" style="width: 100px;" />
                        </span>
                        <span id="weekLabel">
                            <label class="item-label">报告周：</label>
                        	<input type="text" id="week" name="reportWeek" class="easyui-combobox" style="width: 100px;"/>
                        </span>
                        <label class="item-label">渠道：</label>
                        <input type="text" id="channel" name="channelCode" class="easyui-combobox" style="width: 100px;" />
                        <a href="javascript:void(0);" class="easyui-linkbutton c8" style="width:80px;margin-left:40px;" onclick="searchBy()">查询</a>
                    </div>
                </form>
            </div>
            <div class="table-wrapper">
                <table id="datagrid" style="width:100%;" data-options="fitColumns:true,scrollbarSize:0">
                    <thead>
                    <tr>
                        <th data-options="field:'channelName',align:'center'" width="100">渠道</th>
                        <th data-options="field:'code',align:'center'" width="120">报告编码</th>
                        <th data-options="field:'reportType',align:'center',formatter:reportTypeFormatter" width="80">报告类型</th>
                        <th data-options="field:'reportYear',align:'center'" width="80">报告年份</th>
                        <th data-options="field:'reportMonth',align:'center'" width="80">报告月份</th>
                        <th data-options="field:'reportWeek',align:'center'" width="80">报告周</th>
                        <th data-options="field:'reportStatus',align:'center',formatter:reportStatusFormatter" width="80">报告状态</th>
                        <th data-options="field:'action',formatter:actions,align:'center'" width="100">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    </body>
    <script type="text/javascript">
        $(function(){
            //setNav();
            var height = $(window).height();
            var nav_height = $("#nav")._outerHeight();
            var form_height = $("#ff").height();
            $("#datagrid").css("max-height",(height-nav_height-form_height-40));
            initChannelSelect("channel");
            $.when(initMonthWeek("monthLabel","weekLabel")).done(function () {
                searchBy();
            });
            aRecords("数据推送","/webapp/pages/channel/salesDetail/push")
        });
        function actions(val,row){
            return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:80px;height:24px;line-height: 24px;' onclick='disableOne(\""+row.code+"\")'>推送数据</a>";
        }
        function disableOne(id){
            $.messager.confirm("提示","您确定推送记录吗？",function(flag){
                if(flag){
                    $.ajax({
                        url:config.url+"/dataReport/push/"+id,
                        type:'post',
                        data:{"reportStatus":"PRODUCT"},
                        xhrFields:{withCredentials:true},
                        success:function(data){
                            $.messager.alert("提示","操作成功","info",function(){
                                searchBy();
                            });
                        },
                        error:function(XMLHttpRequest,textStatus,thrown){
                            $.messager.alert("提示","操作失败","error");
                        }
                    });
                }
            });
        }
        function edit(id){
            window.location.href="/webapp/pages/channel/upload/edit.html?id="+id;
        }
        function manage(id){
            window.location.href="/webapp/pages/channel/upload/import.html?id="+id;
        }
        function searchBy(page,size){
            var data = getFormData(document.getElementById("ff"));
            data['page'] = page||1;
            data['size'] = size||100;
            data['reportType'] = window.parent.workMode.toUpperCase();
            $.ajax({
                url:config.url + "/dataReport/page",
                type:"get",
                data:transfer(data),
                xhrFields:{withCredentials:true},
                beforeSend:function () {
                    $.messager.progress({
                        title:"请稍等",
                        interval:50,
                        text:"数据加载中..."
                    });
                },
                success:function(data){
                    $("#datagrid").datagrid("loadData",data);
                    $.messager.progress("close");
                },
                error:function(data){
                    console.log(data);
                    $.messager.progress("close");
                }
            });
        }
    </script>
    <script type="text/javascript">
         $(function () {
            setNav();
            $("#datagrid").datagrid({
                 pagination:true,
                 rownumbers:true,
                 checkOnSelect:false,
                 toolbar:[{
                     text:"添加报告",
                     handler:function(){
                         window.parent.addTab("添加报告","/webapp/pages/channel/upload/add.html");
                     }
                 }]
            });
         });
    </script>
</html>